<template>
  <div class="container-pt">
    <van-nav-bar left-arrow  @click-left="$router.back()" fixed title="我的点赞"/>

    <van-list
      v-model="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="onLoad"
    >
   <article-list :disable-swiper="false" v-for="(item,index) in list" :key="index" :item="item">
     <van-button square type="warning" text="取消" @click="changeType(2,item.id)"/>
    </article-list>
</van-list>
   
  </div>
</template>

<script>
import articleList from '@/components/article-list.vue'
import {userCollect} from '../../api/user'
import {setCollect} from '../../api/detail'
export default {
  components: { articleList },
  data() {
    return {
      active:0,
      page:1,
      limit:10,
      list:[],
      loading: false,
      finished: false,
      totalPages:0
    };
  },
   async created(){
  },
  methods:{
    async onLoad() {
          // console.log(1212);
      // 异步更新数据
        const res =  await userCollect({type:2,page:this.page,limit:this.limit})
        console.log(res);
          this.list.push(...res.data.list.data)
          this.totalPages = res.data.list.totalPages || 0
      // await this.$store.commit('indexList/updatePage')
      // await this.$store.dispatch('indexList/getNewList')
      this.page++
      // 加载状态结束
        this.loading = false;

        // 数据全部加载完成
        if (this.page >= this.totalPages) {
          this.finished = true;
        }
    },
       async changeType(type,id){
        await setCollect({type,article_id:id,action:"del"})
       this.$toast('取消收藏')
      //  this.page = 1
       this.list = this.list.filter(item => item.id !== id)
      //  this.list = []
      //  this.finished = false
      //  this.onLoad()
      }
  }
};
</script>

<style>

</style>